//
//  XLBaseVC.m
//  XLBaseDemo
//
//  Created by 薛磊 on 2018/4/18.
//  Copyright © 2018年 薛磊. All rights reserved.
//

#import "XLBaseVC.h"
#import "XLBaseCell.h"
#import <MBProgressHUD/MBProgressHUD.h>

@interface XLBaseVC ()<UITableViewDelegate,UITableViewDataSource>


@end

@implementation XLBaseVC

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
        _tableView.backgroundColor = self.view.backgroundColor;
        _tableView.estimatedRowHeight = 60;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //self.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    
    [self xl_reloadData];
    
    [self xl_setUI];
    
    
}

-(void)xl_setUI{}
-(void)xl_reloadData{}
#pragma mark -按钮提示框-
-(void)showNetworkIndicator{
    UIApplication *app=[UIApplication sharedApplication];
    app.networkActivityIndicatorVisible=YES;
}

-(void)hideNetworkIndicator{
    UIApplication *app=[UIApplication sharedApplication];
    app.networkActivityIndicatorVisible=NO;
}

-(void)showProgress {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self showNetworkIndicator];
}

-(void)hideProgress {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [self hideNetworkIndicator];
}
- (void)toast:(NSString *)text{
    
    [self toast:text duration:2];
}
- (void)toast:(NSString *)text duration:(NSTimeInterval)duration {
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.detailsLabel.font = [UIFont systemFontOfSize:14];
    hud.detailsLabel.text = text;
    hud.margin = 10.f;
    hud.bezelView.layer.cornerRadius = 5.f;
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = MBProgressHUDModeText;
    [hud hideAnimated:YES afterDelay:duration];
}
-(void)showHUDText:(NSString*)text{
    [self toast:text];
}
#pragma mark -创建dataSource-
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XLBaseCell * cell = [XLBaseCell initWithTableView:tableView];
    return cell;
}
@end
